package bbalgae_JavaJDBC;

import java.util.Scanner;
/*
 * 성적데이터를 Scanner 클래스로입력받고 총점 평균 학점을 계산한후 그결과를 SungJukVO에 저장하고
 * SungJukDAO로 그것을 넘김
 */
public class Ex01_SungJukService implements Ex01_ISungJukService {
	Ex01_SungJukVO sj = new Ex01_SungJukVO();
	private Ex01_SungJukDAO ssj = new Ex01_SungJukDAO();
	//private Ex01_ISungJukDAO sjdao =null;
	//public Ex01_SungJukService sjdao = new Ex01_SungJukService();
	
	@Override
	public void createSungJuk() {
		

		Scanner scan = new Scanner(System.in);
	//	System.out.println("번호");
		//sj.setSjno(scan.nextInt());
		System.out.println("이름");
		sj.setName(scan.next());
		System.out.println("국어");
		sj.setKor(scan.nextInt());
		System.out.println("영어");
		sj.setEng(scan.nextInt());
		System.out.println("수학");
		sj.setMat(scan.nextInt());
		
		totalSungJuk(sj);
		avgSungJuk(sj);
		grdSungJuk(sj);
	
		if (ssj.insertSungJuk(sj))
			System.out.println("성공 !");
		else
			System.out.println("실패");	
		
		
	}
		
			

		@Override
		public void totalSungJuk(Ex01_SungJukVO sj) {
			sj.setTot(sj.getKor()+sj.getEng()+sj.getMat());
		}

		@Override
		public void avgSungJuk(Ex01_SungJukVO sj) {
		
			sj.setAvg(sj.getTot()/3);
		}

		@Override
		public void grdSungJuk(Ex01_SungJukVO sj) {
		
			String a="";
				
			switch((int)sj.getAvg()/10){
			
			case 10: a="수"; break;
			case 9: 
			case 8: a="우"; break;
			case 7: a="미";break;
			case 6: a="양";break;
			default :
				a="가";break;
			
					
			}	sj.setGrd(a);
		
		}



		@Override
		public void readSungJuk() {
			for(Ex01_SungJukVO s:ssj.selectSungJuk()){
				System.out.print(s.getSjno()+"\t");
				System.out.print(s.getName()+"\t");
				System.out.print(s.getKor()+"\t");
				System.out.print(s.getEng()+"\t");
				System.out.print(s.getMat()+"\t");
				System.out.print(s.getTot()+"\t");
				System.out.print(s.getAvg()+"\t");
				System.out.println(s.getGrd());
				
				
				
			}
			
		}



		@Override
		public void modifySungJuk() {
			Scanner scan = new Scanner(System.in);
			Ex01_SungJukVO sj = new Ex01_SungJukVO();

			readSungJuk();
			System.out.println("수정할 학생 번호 입력");
			sj.setSjno(scan.nextInt());
			System.out.println("이름 수정");
			sj.setName(scan.next());
			System.out.println("국어 수정");
			sj.setKor(scan.nextInt());
			System.out.println("영어 수정");
			sj.setEng(scan.nextInt());
			System.out.println("수학 수정");
			sj.setMat(scan.nextInt());
			this.totalSungJuk(sj);
			this.avgSungJuk(sj);
			this.grdSungJuk(sj);
			//sj.setTot(sj.getTot());
		
	
		
			if(ssj.updateSungJuk(sj))
				System.out.println("수정성공");
			else
				System.out.println("수정실패");
		}



		@Override
		public void deleteSungJuk() {
			Scanner scan = new Scanner(System.in);
			Ex01_SungJukVO sj = new Ex01_SungJukVO();
			readSungJuk();
			
			System.out.println("삭제할번호 입력");
			sj.setSjno(scan.nextInt());
			
			if(ssj.deleteSungJuk(sj))
				System.out.println("삭제성공");
			else
				System.out.println("실패");
		}
	
			
}


